package com.scorpio.goods.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.scorpio.goods.service.IGoodsSkuSpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.scorpio.goods.mapper.GoodsSkuMapper;
import com.scorpio.goods.domain.GoodsSkuEntity;
import com.scorpio.goods.service.IGoodsSkuService;
import com.scorpio.common.service.impl.BaseServiceImpl;
import org.springframework.transaction.annotation.Transactional;

/**
 * 商品sku分组Service业务层处理
 *
 * @author scorpio
 * @date 2021-10-29
 */
@Service
public class GoodsSkuServiceImpl extends BaseServiceImpl<GoodsSkuMapper, GoodsSkuEntity> implements IGoodsSkuService {

    @Autowired
    private IGoodsSkuSpecService skuSpecService;


    @Override
    public List<GoodsSkuEntity> selectSkuBySpec(Long specId) {
        List<Long> ids = skuSpecService.selectSkuIdsBySpec(specId);
        if (ids.size() == 0) {
            return new ArrayList<>();
        }
        return baseDao.selectByids(ids);
    }

    @Override
    public List<GoodsSkuEntity> selectByGoods(Long goodsId) {
        return baseDao.selectByGoods(goodsId);
    }

    //查询
    @Override
    public GoodsSkuEntity selectById(Long id) {
        return baseDao.selectById(id);
    }

    //查询列表
    @Override
    public List<GoodsSkuEntity> selectList(GoodsSkuEntity entity) {
        return baseDao.list(entity);
    }

    //新增$
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int save(GoodsSkuEntity entity) {
        return baseDao.insert(entity);
    }

    @Override
    public int updateSort(Long id, Integer sort) {
        return baseDao.updateSort(id, sort);
    }

    //修改
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int update(GoodsSkuEntity entity) {
        return baseDao.updateById(entity);
    }

    //批量删除
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int deleteByIds(Long[] ids) {
        return baseDao.updateDelete(ids);
    }

    @Override
    public List<GoodsSkuEntity> selectDeleteNotContain(Long goodsId, List<Long> ids) {
        return baseDao.selectDeleteNotContain(goodsId, ids);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateDeleteNotContain(Long goodsId, List<Long> ids) {
        return baseDao.updateDeleteNotContain(goodsId, ids);
    }
}
